package com.example.vae.Adapter;

import android.content.Context;
import android.util.DisplayMetrics;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;
import androidx.annotation.NonNull;
import androidx.recyclerview.widget.RecyclerView;

import com.example.vae.R;

import java.util.List;

//这个是初始化Find 页面的 Adapter
public class FindRecyclerViewAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder> {

    Context context;
    private LayoutInflater layoutInflater;
    private List<Integer> imageviews;
    private List<String> strings;

    public FindRecyclerViewAdapter(Context context){
        this.context = context;
    }
    public FindRecyclerViewAdapter(Context context, List<Integer> imageviews, List<String> strings){
        this.context=context;
        this.imageviews=imageviews;
        this.strings=strings;
        layoutInflater=LayoutInflater.from(context);
    }

    //    初始化item布局
    @NonNull
    @Override
    public RecyclerView.ViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {

       View view=layoutInflater.inflate(R.layout.re_item,parent,false);
        DisplayMetrics dm=context.getResources().getDisplayMetrics();
        int height=dm.heightPixels;
        view.getLayoutParams().height=height/10;
        MyViewHolder myViewHolder=new MyViewHolder(view);
        return myViewHolder;
    }

    //    处理每一个item 的地方,绑定数据
    @Override
    public void onBindViewHolder( RecyclerView.ViewHolder holder, int position) {

        MyViewHolder myViewHolder=(MyViewHolder)holder;
        myViewHolder.imageView.setImageResource(imageviews.get(position));
        myViewHolder.textView.setText(strings.get(position));

    }

    //    显示数量，因为我的布局文件就是三个，所以我返回san
    @Override
    public int getItemCount() {
        return imageviews.size();
    }

    public class MyViewHolder extends RecyclerView.ViewHolder{

        private ImageView imageView;
        private TextView textView;

        public MyViewHolder(@NonNull View itemView) {
            super(itemView);
            imageView=itemView.findViewById(R.id.iv);
            textView=itemView.findViewById(R.id.tv);
        }
    }

}